package com.panopset.map;

import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;

/**
 * Map wrapper with a map name.
 * @author Karl Dinwiddie
 *
 * @param <K>
 * @param <V>
 */
public class NamedMap<K,V> {
    private final String name;
    private final Map<K,V> map;

    public NamedMap(String name) {
        this(name, Collections.synchronizedMap(new TreeMap<K,V>()));
    }

    public NamedMap(String name, Map<K, V> map) {
        this.name = name;
        this.map = map;
    }

    public void put(K key, V value) {
        KeyReporter.singleton.reportDefinedKey(name, key.toString());
        map.put(key, value);
    }

    public V get(K key) {
        KeyReporter.singleton.reportUsedKey(name,key.toString());
        return map.get(key);
    }
}
